package com.logistics.map.controller;

import com.logistics.map.entity.model.MapRoutePager;
import com.logistics.map.entity.model.MapRouteSave;
import com.logistics.map.service.MapRouteService;
import com.logistics.utils.exception.MessageException;
import com.logistics.utils.response.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("lgs/map/route")
public class MapRouteController {

    @Autowired
    private MapRouteService mapRouteService;


    /**
     * 查找列表
     * @param param
     * @return
     */
    @PostMapping("pager")
    public ResponseEntity pager(@RequestBody MapRoutePager param){
        return ResponseUtil.success(mapRouteService.pager(param));
    }

    /**
     * 根据地图ID查找列表
     * @param mapId
     * @return
     */
    @GetMapping("listByMapId/{mapId}")
    public ResponseEntity listByMapId(@PathVariable("mapId") String mapId){
        return ResponseUtil.success(mapRouteService.listByMapId(mapId));
    }

    /**
     * 查找详细
     * @param id
     * @return
     * @throws MessageException
     */
    @GetMapping("details/{id}")
    public ResponseEntity details(@PathVariable("id") String id) throws MessageException {
        return ResponseUtil.success(mapRouteService.details(id));
    }

    /**
     * 保存
     * @param save
     * @return
     */
    @PutMapping("save")
    public ResponseEntity save(@RequestBody MapRouteSave save){
        mapRouteService.save(save);
        return ResponseUtil.success();
    }

    /**
     * 删除
     * @param ids
     * @return
     * @throws MessageException
     */
    @DeleteMapping("remove/{ids}")
    public ResponseEntity remove(@PathVariable("ids") String ids) throws MessageException {
        mapRouteService.delete(ids);
        return ResponseUtil.success();
    }
}
